<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-03-28
 * Time: 下午 4:39
 */
namespace Model;

class ActivityMod extends Mod
{
	public function __construct()
	{
		$this->_table = 'kuyuan_vbz_activity';
	}

	/**
	 * 前端获取活动列表
	 * @param $_limit
	 */
	public function ali($_limit)
	{
		global $_W;
		$_sql = "
				SELECT 
						id,name,cover,start,end,address
				FROM
					".tablename($this->_table)."
				WHERE
					uniacid = :uniacid
				AND
					status = 1
				ORDER BY 
					start <=".TIMESTAMP." AND end > ".TIMESTAMP." DESC,
					start > ".TIMESTAMP." DESC
				LIMIT
					{$_limit[0]},{$_limit[1]}
				";
		return pdo_fetchall($_sql,array('uniacid'=>$_W['account']['uniacid']));
	}

    /**
     * 前端获取活动列表
     * @param $_limit
     * @param array $_search 搜索相关内容
     * @return mixed
     */
    public function storeList($_limit,Array $_search = array())
    {
        global $_W;
        $_str_where = ' uniacid = :uniacid AND status != 9 AND end > '.TIMESTAMP.' AND shop_model = 1 ';
        $_bind = array('uniacid'=>$_W['account']['uniacid']);
        if(count($_search) > 0){
            if($_search['search_type'] == 'id'){
                $_str_where .= "AND id = :id ";
                $_bind['id'] = $_search['search_keyword'];
            }else if($_search['search_type'] == 'name'){
                $_str_where .= "AND name like :name ";
                $_bind['name'] = '%'.$_search['search_keyword'].'%';
            }else{
                $_str_where .= "AND address like :address ";
                $_bind['address'] = '%'.$_search['search_keyword'].'%';
            }
        }
        $_sql = "
				SELECT 
						id,name,cover,start,end,address
				FROM
					".tablename($this->_table)."
				WHERE
					".$_str_where."
				ORDER BY 
					start <=".TIMESTAMP." AND end > ".TIMESTAMP." DESC,
					start > ".TIMESTAMP." DESC
				LIMIT
					{$_limit[0]},{$_limit[1]}
				";
        return pdo_fetchall($_sql,$_bind);
    }

}